package com.example.studyktdemo.uitls

import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit

class OkhttpUtils{

    companion object {
        var mInstance: OkhttpUtils? = null

        var mClient: OkHttpClient.Builder? = null
    }

    constructor(){
        mClient = OkHttpClient().newBuilder()
        //设置链接、读取、写入超时
        //设置链接、读取、写入超时
        mClient?.connectTimeout(20, TimeUnit.SECONDS)
        mClient?.readTimeout(60, TimeUnit.SECONDS)
        mClient?.writeTimeout(60, TimeUnit.SECONDS)
    }

    fun getInstance(): OkhttpUtils? {
        if (mInstance == null) {
            synchronized(OkhttpUtils::class.java) {
                if (mInstance == null) {
                    mInstance = OkhttpUtils()
                }
            }
        }
        return mInstance
    }
}